package org.jtzc.springaiagent.controller;

import jakarta.annotation.Resource;
import org.jtzc.springaiagent.agent.BaseAgent;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

/**
 * @author wu chuang
 * @description
 */
@RestController
public class AIController {
    @Resource(name = "openAiAgent")
    private BaseAgent openAiAgent;

    /**
     * 单一LLM
     */
    @GetMapping("/ask")
    public ResponseEntity<BaseAgent.AgentResponse> askQuestion(String msg) {
        BaseAgent.AgentRequest request = new BaseAgent.AgentRequest(msg, Map.of("model", "gpt-4"));
        BaseAgent.AgentResponse response = openAiAgent.execute(request);
        return ResponseEntity.ok(response);
    }

    /**
     * 链式
     */

    @Resource(name = "chainedAgent")
    private BaseAgent orderProcessingChain;

    @GetMapping("/chain")
    public ResponseEntity<BaseAgent.AgentResponse> chain(String msg) {
        BaseAgent.AgentRequest request = new BaseAgent.AgentRequest(msg, Map.of("process", "order"));
        BaseAgent.AgentResponse response = orderProcessingChain.execute(request);
        return ResponseEntity.ok(response);
    }

    @Resource(name = "routerAgent")
    private BaseAgent routerAgent;
    @GetMapping("/router")
    public ResponseEntity<BaseAgent.AgentResponse> router(String msg) {
        BaseAgent.AgentRequest request = new BaseAgent.AgentRequest(msg, Map.of("router", "router"));
        BaseAgent.AgentResponse response = routerAgent.execute(request);
        return ResponseEntity.ok(response);
    }

    @Resource(name = "reflectiveAgent")
    private BaseAgent reflectiveAgent;
    @GetMapping("/reflective")
    public ResponseEntity<BaseAgent.AgentResponse> reflective(String msg) {
        BaseAgent.AgentRequest request = new BaseAgent.AgentRequest("Write a comprehensive article about: " + msg, Map.of("Reflective", "Reflective"));
        BaseAgent.AgentResponse response = reflectiveAgent.execute(request);
        return ResponseEntity.ok(response);
    }

    @Resource(name = "planningAgent")
    private BaseAgent planningAgent;
    @GetMapping("/planning")
    public ResponseEntity<BaseAgent.AgentResponse> planning(String msg) {
        BaseAgent.AgentRequest request = new BaseAgent.AgentRequest( msg, Map.of("planning", "planning"));
        BaseAgent.AgentResponse response = reflectiveAgent.execute(request);
        return ResponseEntity.ok(response);
    }

    @Resource(name = "collaborativeAgentGroup")
    private BaseAgent collaborativeAgentGroup;
    @GetMapping("/collaborative")
    public ResponseEntity<BaseAgent.AgentResponse> collaborative(String msg) {
        BaseAgent.AgentRequest request = new BaseAgent.AgentRequest(
                "Prepare a comprehensive report on: " + msg,
                Map.of("format", "APA", "length", "2000 words")
        );
        BaseAgent.AgentResponse response = collaborativeAgentGroup.execute(request);
        return ResponseEntity.ok(response);
    }


    @Resource(name = "adaptiveAgent")
    private BaseAgent adaptiveAgent;
    @GetMapping("/adaptive")
    public ResponseEntity<BaseAgent.AgentResponse> adaptive(String msg) {
        BaseAgent.AgentRequest request = new BaseAgent.AgentRequest(
                 msg,
                Map.of("adaptive", "adaptive")
        );
        BaseAgent.AgentResponse response = adaptiveAgent.execute(request);
        return ResponseEntity.ok(response);
    }



    @Resource(name = "statefulAgent")
    private BaseAgent statefulAgent;
    @GetMapping("/stateful")
    public ResponseEntity<BaseAgent.AgentResponse> stateful(String msg) {
        BaseAgent.AgentRequest request = new BaseAgent.AgentRequest(
                msg,
                Map.of("stateful", "stateful")
        );
        BaseAgent.AgentResponse response = statefulAgent.execute(request);
        return ResponseEntity.ok(response);
    }


}
